import EditDialog from '@/pages/Shop/Taocan/editDialog';
import { findByTaoCanPageList } from '@/services/taocan';
import { defaultPagination } from '@/utils/util';
import ProTable from '@ant-design/pro-table';
import { useMount, useRequest } from 'ahooks';
import { useState } from 'react';

//
const cloneTbale = () => {
  const [pagination, setPagination] =
    useState<API.Pagination>(defaultPagination());
  const {
    run: fetchByPageList,
    refresh,
    data: dataList,
    loading,
  } = useRequest(findByTaoCanPageList, {
    debounceWait: 100,
    manual: true,
  });

  const columns = [
    {
      title: '编号',
      key: 'id',
      dataIndex: 'id',
      search: false,
    },
    {
      title: '套餐名称',
      key: 'name',
      dataIndex: 'name',
    },
    {
      title: '当前等级',
      dataIndex: 'relationAgentName',
      key: 'relationAgentName',
      search: false,
    },
    {
      title: '下单代理等级',
      dataIndex: 'agentName',
      key: 'agentName',
      search: false,
    },
    {
      title: '支付金额',
      key: 'paymentAmount',
      dataIndex: 'paymentAmount',
      valueType: 'money',
      search: false,
    },
    {
      title: '优惠金额',
      key: 'discountAmount',
      dataIndex: 'discountAmount',
      valueType: 'money',
      search: false,
    },
    {
      title: '支付总额',
      key: 'totalAmount',
      dataIndex: 'totalAmount',
      valueType: 'money',
      search: false,
    },
    {
      title: '产品总数',
      key: 'quantity',
      dataIndex: 'quantity',
      search: false,
    },
    {
      title: '时间',
      key: 'createDate',
      dataIndex: 'createDate',
      valueType: 'date',
      search: false,
      // initialValue: [moment().calendar(), moment().add(10, 'days').calendar()],
    },
    {
      title: '时间',
      key: 'createDate',
      dataIndex: 'createDate',
      valueType: 'dateRange',
      hideInTable: true,
      // initialValue: [moment().calendar(), moment().add(10, 'days').calendar()],
    },
    {
      title: '操作人员',
      key: 'operatorName',
      dataIndex: 'operatorName',
      search: false,
    },
    {
      title: '操作',
      key: 'operatorName',
      dataIndex: 'operatorName',
      search: false,
      render: (_: any, row: API.TaoCanMaster, index: any, action: any) => [
        <EditDialog taocanId={row?.id} row={row} onSuccess={refresh} />,
      ],
    },
  ];
  useMount(() => {
    //  fetchByPageList ({});
  });

  // @ts-ignore
  return (
    <ProTable<API.TaoCanMaster>
      toolBarRender={() => [<EditDialog taocanId={0} onSuccess={refresh} />]}
      rowKey="id"
      search={{
        defaultCollapsed: false,
        labelWidth: 'auto',
      }}
      onSubmit={(params) => {
        fetchByPageList(params);
        console.log('onSubmit', params);
      }}
      cardBordered={true}
      columns={columns}
      request={findByTaoCanPageList}
    ></ProTable>
  );
};

export default cloneTbale;
